import Vue from 'vue'
export default {
	state: {
		List: [{
				name: '王贵',
				phone: '18225517585',
				email: '15551245@qq.com',
				path: '',
				province: '安徽省',
				city: '合肥市',
				district: '新站区',
				address: '华润熙云府5#502',
				default: 1
			},
			{
				name: '安娜',
				phone: '18985623589',
				email: '3596852455@qq.com',
				path: '',
				province: '安徽省',
				city: '合肥市',
				district: '高新区',
				address: '保利梧桐语6#703',
				default: 0
			}
		]
	},
	mutations: {
		//删除
		getAddressDel(state,i){
			uni.showModal({
				title: '提示',
				content: '您确定要删除该列表吗',
				success:  (res)=> {
					if (res.confirm) {
						state.List.splice(i,1)
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});

		},
		//编辑
		getAddressEdit(state, {
			index,
			item
		}) {
			console.log('111111111111111', index, item);
			// state.List[index] = item  不能通过修改下标得形式对数组进行修改

			Vue.set(state.List, index, item)
			if (state.List[index].default == 1) {
				state.List.forEach(v => v.default = 0)
				state.List[index].default = 1
			}
			
			console.log('state.List', state.List[index]);
		},
		//新增
		getAddressAdd(state,payload){
			console.log('payload',payload);
			state.List.unshift(payload)
			if (payload.default) {
				state.List.forEach(v => v.default = 0)
				payload.default = 1
			}
		}
	},
	getters: {

	},
	actions: {

	}
}